package com.xy.biz.xd.controller;

import com.xy.biz.xd.domain.req.*;
import com.xy.biz.xd.service.DocumentFlowNewAndModifyService;
import com.xy.biz.xd.service.DocumentFlowNewService;
import com.xy.lang.domain.Result;
import com.xy.lang.validation.UpdateChecks;
import com.xy.lang.validation.annotation.Validatable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "文档流程服务-新增流程")
@Slf4j
@RequestMapping("/api/xd/document_flow_new")
@RestController
public class DocumentFlowNewController extends AbstractDocumentFlowNewAndModifyController {

    @Autowired
    private DocumentFlowNewService documentFlowNewService;

    @Resource(name = "documentFlowNewServiceImpl")
    @Override
    protected void setDocumentFlowNewAndModifyService(DocumentFlowNewAndModifyService documentFlowNewAndModifyService) {
        this.documentFlowNewAndModifyService = documentFlowNewAndModifyService;
    }

    @ApiOperation("申请")
    @Validatable
    @PostMapping(value = "/apply")
    public Result<?> applyDocumentFlow(@RequestBody ApplyDocumentFlowNewRequest request) {
        return documentFlowNewService.saveDocumentFlow(request);
    }

    @Deprecated
    @ApiOperation("上传文件")
    @Validatable(groups = {UpdateChecks.class})
    //@PostMapping(value = "/upload")
    public Result<?> uploadDocumentFlow(@RequestBody UploadDocumentFlowNewRequest request) {
        return documentFlowNewService.uploadDocumentFlow(request);
    }

    @ApiOperation("放行")
    @Validatable
    @PostMapping(value = "/release")
    public Result<?> releaseDocumentFlow(@RequestBody ReleaseDocumentFlowNewRequest request) {
        return documentFlowNewService.releaseDocumentFlow(request);
    }

    @ApiOperation("重更新修改生效日期")
    @Validatable
    @PostMapping(value = "/update_effect_date")
    public Result<?> updateEffectDate(@RequestBody UpdateDocumentFlowRequest request) {
        return documentFlowNewService.updateEffectDate(request);
    }

}
